package com.jctrip.hotel.source.xxl.atour;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jctrip.hotel.common.constant.XxlJobNameConstant;
import com.jctrip.hotel.common.util.JsonUtil;
import com.jctrip.hotel.domain.dao.HtSourceInfoDao;
import com.jctrip.hotel.domain.entity.HtSourceInfo;
import com.jctrip.hotel.source.model.CommonJobParam;
import com.jctrip.hotel.source.service.atour.AtourTaskService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author henry
 * @Date 2023/6/3 15:52
 * @Description
 */
@Slf4j
@Component
public class SyncAtourHotelInfoListTaskFastPopXxlJob extends IJobHandler {
    @Resource
    private AtourTaskService atourTaskService;
    @Resource
    private HtSourceInfoDao htSourceInfoDao;
    @Override
    @XxlJob(XxlJobNameConstant.SYNC_ATOUR_HOTEL_INFO_POP)
    public void execute() throws Exception {
        XxlJobHelper.log(XxlJobNameConstant.SYNC_ATOUR_HOTEL_INFO_POP + " xxl job start");
        try {
            CommonJobParam jobParam = JsonUtil.toObject(CommonJobParam.class, XxlJobHelper.getJobParam());
            HtSourceInfo htSourceInfo =
                    htSourceInfoDao.selectOne(new LambdaQueryWrapper<HtSourceInfo>().eq(HtSourceInfo::getSourceId,
                            jobParam.getSourceId()));
            if (htSourceInfo == null) {
                return;
            }
            atourTaskService.syncAtourHotelInfoListTaskFastPop(Integer.valueOf(htSourceInfo.getSourceAppId()),
                    htSourceInfo.getSourceSecret());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        XxlJobHelper.log(XxlJobNameConstant.SYNC_ATOUR_HOTEL_INFO_POP + " xxl job end");
    }
}
